package com.totcy.atom.presenter;

import android.content.Context;

import com.totcy.atom.bean.ImagesBean;
import com.totcy.atom.model.ImageGridModel;
import com.totcy.atom.presenter.contract.ImageGridContract;
import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;

import java.util.List;

/**
 * description: xxxiao分类列表 个人图片List presenter
 * author: Totcy
 * date: 2017/11/4 21:45
 * update: 2017/11/4
 */

public class ImageGridPresenter extends BasePresenterImpl<ImageGridContract.View, ImageGridContract.Model> implements ImageGridContract.Presenter{

    public ImageGridPresenter(Context context) {
        super(context);
    }

    @Override
    public ImageGridContract.Model attachModel() {
        return new ImageGridModel(mContext);
    }


    /**
     * Presenter 调用 model 获取数据
     *
     * @param url 链接
     */
    @Override
    public void getImagesData(String url) {
        if (isModelAttached()) {
            getModel().getImagesData(url, new ImageGridContract.Model.DataCallback() {
                @Override
                public void onDataSuccess(List<ImagesBean> beans) {
                    if (isViewAttached()) {
                        getView().onImagesData(beans);
                    }
                }

                @Override
                public void onDataNotAvailable() {
                    if (isViewAttached()) {
                        getView().onDataFail();
                    }
                }
            });
        }
    }
}
